﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EvoGame.Ceeforee.CivilizationPanels
{
	public partial class CitiesPanel : CivPanel
	{
		MainWin mWin;

		public CitiesPanel()
		{
			InitializeComponent();
		}

		public CitiesPanel(MainWin mw)
		{
			mWin = mw;
			InitializeComponent();
		}

		public override void Update()
		{
			citiesList.Items.Clear();
			citiesList.Items.AddRange(mWin.selectedCiv.Cities.ToArray());
			base.Update();
		}

		private void citiesList_SelectedIndexChanged(object sender, EventArgs e)
		{
			cityName.Text = mWin.civDB.GetTXTKey(mWin.selectedCiv.Cities.ToArray()[citiesList.SelectedIndex]);
		}

		private void cityName_ModifiedChanged(object sender, EventArgs e)
		{
			mWin.selectedCiv.Modified = true;
			string txtKey = string.Format("TXT_KEY_CITY_NAME_{0}", cityName.Text.ToUpper());
			mWin.selectedCiv.Cities[citiesList.SelectedIndex] = txtKey;
			mWin.civDB.AddTXTKey(txtKey, cityName.Text);
			cityName.Modified = false;
		}

		private void cityName_LeaveFocus(object sender, EventArgs e)
		{
			Update();
		}

	}
}
